<script setup lang="ts">
import {onMounted} from "vue";
import {useCategoryStore} from "@/stores/modules/category.ts";
import {storeToRefs} from "pinia";

defineProps({
  scene:{
    type:Boolean,
    default:true
  }
})

const categoryStore = useCategoryStore()
const {category1, C1Id, category2, C2Id, category3, C3Id} = storeToRefs(categoryStore)

onMounted(()=>{
  categoryStore.getC1()
})

const getC2 = () => {
  categoryStore.$patch((state)=>{
    state.C2Id = ''
    state.C3Id = ''
    state.category3 = []
  })
  categoryStore.getC2()
}

const getC3 = () => {
  categoryStore.$patch((state) => {
    state.C3Id = ''
  })
  categoryStore.getC3()
}

</script>

<template>
  <el-card>
    <el-form :inline="true" style="display: flex;justify-content: space-around ">
      <el-form-item label="一级分类">
        <el-select :disabled="!scene" v-model="C1Id" @change="getC2()">
          <el-option v-for="c1 in category1" :key="c1.id" :label="c1.name" :value="c1.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="二级分类">
        <el-select :disabled="!scene" v-model="C2Id" @change="getC3()">
          <el-option v-for="c2 in category2" :key="c2.id" :label="c2.name" :value="c2.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="三级分类">
        <el-select :disabled="!scene" v-model="C3Id">
          <el-option v-for="c3 in category3" :key="c3.id" :label="c3.name" :value="c3.id"></el-option>
        </el-select>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<style scoped lang="scss">

</style>